import { createSlice } from "@reduxjs/toolkit";
const counterStore = createSlice({
  name: "counter",
  // 初始化状态
  initialState: {
    count: 0,
  },
  // 定义修改状态的方法，支持直接修复
  reducers: {
    increment(state) {
      state.count++;
    },
    decrement(state) {
      state.count--;
    },
    addToNum(state, action) {
      state.count += action.payload;
    },
  },
});

// 解构出来actionCenter函数
const { increment, decrement, addToNum } = counterStore.actions;
// 获取reducer
const counterReducer = counterStore.reducer;

// 以按需导出的方式导出action
export { increment, decrement, addToNum };
// 以默认导出的方式导出reducer
export default counterReducer;
